#!/bin/bash
echo "Begin"
#开始 安装wget vim
if [[ `command -v wget` == "" ]] ;then
  yum install -y wget
fi
if [[ `command -v vim` == "" ]] ;then
  yum install -y vim
fi
# 创建frp目录
frpdir="/home/frp"
if [ ! -d $frpdir ];then
  mkdir $frpdir
fi
#下载frp
if [ ! -f $frpdir/frp_0.38.0_linux_amd64.tar.gz ];then
  wget -N -P $frpdir https://gitee.com/yifff/cent-os-init/attach_files/894908/download/frp_0.38.0_linux_amd64.tar.gz
  if [ $? -ne 0 ]; then
    echo "wget frp fail exit"
    exit 8
  fi
fi
#解压 如果有目录，就不解压
if [ ! -d $frpdir/frp_0.38.0_linux_amd64 ];then
  tar -zxvf $frpdir/frp_0.38.0_linux_amd64.tar.gz -C $frpdir
fi

# 开始启动目录
systemstartdir="/lib/systemd/system"
# 下载frp客户端自启
if [ ! -f $systemstartdir/frpc.service ];then
  wget -N -P $systemstartdir https://gitee.com/yifff/cent-os-init/attach_files/898378/download/frpc.service
  if [ $? -ne 0 ]; then
    echo "wget frpc fail exit"
    exit 8
  fi
fi
# 下载frpc服务器自启
if [ ! -f $systemstartdir/frps.service ];then
  wget -N -P $systemstartdir https://gitee.com/yifff/cent-os-init/attach_files/898378/download/frps.service
  if [ $? -ne 0 ]; then
    echo "wget frps fail exit"
    exit 8
  fi
fi

chmod 777 $systemstartdir/frps.service
chmod 777 $systemstartdir/frpc.service
systemctl enable frpc
systemctl start frpc
#安装 docker
if [[ `command -v docker` == "" ]] ;then
  yum install -y yum-utils
  yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
  yum makecache fast
  yum install -y docker-ce
  # 修改默认路径
  dockerdir="/home/docker/"
  mkdir $dockerdir
  mv /var/lib/docker/* $dockerdir
    # 修改默认路径
  dockerdir="/home/docker/"
  mkdir $dockerdir
  mv /var/lib/docker/* $dockerdir
  # 不能用代码进行修改默认路径，需要自己修改
  # vim /usr/lib/systemd/system/docker.service
  sed -i "s/containerd.sock/containerd.sock --graph \/home\/docker/g" /usr/lib/systemd/system/docker.service
  #增加--graph /home/docker
  systemctl daemon-reload
  systemctl enable docker
  systemctl start docker  
fi
systemctl stop firewalld
systemctl disable firewalld
echo "end "
